package osgi.classloader.internal;

import org.eclipse.equinox.servletbridge.BridgeServlet;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import osgi.classloader.ClassLoaderService;
import osgi.classloader.IClassLoaderService;

public class ClassLoaderBundleActivator implements BundleActivator {
	private ServiceRegistration serviceRegistration;

	public void start(BundleContext context) throws Exception {
		// 注册服务
		serviceRegistration = context.registerService(
				IClassLoaderService.class.getName(), new ClassLoaderService(),
				null);
		System.out.println(">>>>> start: "
				+ context.getBundle().getSymbolicName());
		
		BridgeServlet.setBundleClassLoader(this.getClass().getClassLoader());
		//BridgeServlet.setBundleContext(context);
		ClassLoaderService.bundleContext = context;
	}

	public void stop(BundleContext context) throws Exception {
		// 注销服务
		serviceRegistration.unregister();
		ClassLoaderService.classLoader = null;
		ClassLoaderService.bundleContext = null;
	}

}
